<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改优惠券')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-coupon-edit" th:object="${couponInfo}">
        <input name="id" th:field="*{id}" type="hidden">

        <div class="form-group">
            <label class="col-sm-3 control-label">优惠券标题：</label>
            <div class="col-sm-8">
                <input name="title" th:field="*{title}" class="form-control" type="text" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">优惠券类型：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('coupon_type')}">
                    <input type="radio" th:id="${dict.dictCode}" name="type" th:field="*{type}"
                           th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">使用门槛：</label>
            <div class="col-sm-8">
                <input name="reachAmount" th:field="*{reachAmount}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">面额：</label>
            <div class="col-sm-8">
                <input name="faceValue" th:field="*{faceValue}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">折扣值：</label>
            <div class="col-sm-8">
                <input name="discount" th:field="*{discount}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">总发放量：</label>
            <div class="col-sm-8">
                <input name="totalIssuance" th:field="*{totalIssuance}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">已领取数量：</label>
            <div class="col-sm-8">
                <input name="totalGet" th:field="*{totalGet}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">已使用数量：</label>
            <div class="col-sm-8">
                <input name="totalUse" th:field="*{totalUse}" class="form-control" type="text" required>
            </div>
        </div>
        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">领取开始时间：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<div class="input-group date">-->
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <!--<input name="getStartTime" th:value="${#dates.format(couponInfo.getStartTime, 'yyyy-MM-dd')}"-->
                           <!--class="form-control" placeholder="yyyy-MM-dd" type="text">-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">领取结束时间：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<div class="input-group date">-->
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <!--<input name="getEndTime" th:value="${#dates.format(couponInfo.getEndTime, 'yyyy-MM-dd')}"-->
                           <!--class="form-control" placeholder="yyyy-MM-dd" type="text">-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">使用开始时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="useStartTime" th:value="${#dates.format(couponInfo.useStartTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">使用结束时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="useEndTime" th:value="${#dates.format(couponInfo.useEndTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('coupon_status')}">
                    <input type="radio" th:id="${dict.dictCode}" name="couponStatus" th:field="*{couponStatus}"
                           th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否注册赠送：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('is_enable')}">
                    <input type="radio" th:id="${dict.dictCode}" name="isAbleActivity" th:field="*{isAbleActivity}"
                           th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否可用：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('is_enable')}">
                    <input type="radio" th:id="${dict.dictCode}" name="isEnable" th:field="*{isEnable}"
                           th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" name="remark" class="form-control">[[*{remark}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: ztree-js"/>
<script type="text/javascript">
    var prefix = ctx + "back/coupon";

    // $('input').on('ifChecked', function (event) {
    //     if ($(event.target).attr("name") == "subType") {
    //         var radio = $(event.target).val();
    //         if (radio == "0") {
    //             $("#conMaterial").hide();
    //         } else if (radio == "1") {
    //             $("#conMaterial").show();
    //         }
    //     }
    // });

    // $("input[name='getStartTime']").datetimepicker({
    //     format: "yyyy-mm-dd",
    //     minView: "month",
    //     autoclose: true
    // });
    //
    // $("input[name='getEndTime']").datetimepicker({
    //     format: "yyyy-mm-dd",
    //     minView: "month",
    //     autoclose: true
    // });

    $("input[name='useStartTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='useEndTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }

    /*
    * id,title,type,modelType,reachAmount,faceValue,discount,totalIssuance,
    * totalGet,totalUse,getStartTime,getEndTime,useStartTime,useEndTime,couponStatus,isAbleShareGet,isEnable,subType
    *
    * */
    function edit() {
        var id = $("input[name='id']").val();
        var title = $("input[name='title']").val();
        var type = $("input[name='type']:checked").val();
        var imageUrl = $("input[name='imageUrl']").val();
        var reachAmount = $("input[name='reachAmount']").val();
        var faceValue = $("input[name='faceValue']").val();
        var discount = $("input[name='discount']").val();
        var totalIssuance = $("input[name='totalIssuance']").val();
        var totalGet = $("input[name='totalGet']").val();
        var totalUse = $("input[name='totalUse']").val();
        var getStartTime = $("input[name='getStartTime']").val();
        var getEndTime = $("input[name='getEndTime']").val();
        var useStartTime = $("input[name='useStartTime']").val();
        var useEndTime = $("input[name='useEndTime']").val();
        var couponStatus = $("input[name='couponStatus']:checked").val();
        var isAbleActivity = $("input[name='isAbleActivity']:checked").val();
        var isEnable = $("input[name='isEnable']:checked").val();
        var remark = $("#remark").val();

        $.ajax({
            cache: true,
            type: "POST",
            url: prefix + "/edit",
            data: {
                "id": id,
                "title": title,
                "type": type,
                "modelType": modelType,
                "reachAmount": reachAmount,
                "imageUrl": imageUrl,
                "faceValue": faceValue,
                "discount": discount,
                "totalIssuance": totalIssuance,
                "totalGet": totalGet,
                "totalUse": totalUse,
                "getStartTime": getStartTime,
                "getEndTime": getEndTime,
                "useStartTime": useStartTime,
                "useEndTime": useEndTime,
                "couponStatus": couponStatus,
                "isAbleShareGet": isAbleShareGet,
                "isAbleActivity": isAbleActivity,
                "isEnable": isEnable,
                "remark": remark,
                "subType": subType,

                "materialIds": materialIds
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }
</script>
</body>
</html>